import {
  reqCategoryData
} from "../../api/category"
Page({

  //初始化数据
  data: {
    categoryList: [], //商品分类数据
    activeIndex: 0 //被激活项的索引,默认是0
  },
  //获取商品分类的数据
  async getCategoryData() {
    const res = await reqCategoryData()
    if (res.code === 200) {
      this.setData({
        categoryList: res.data
      })
    }
  },
  //实现一级分类的切换效果
  updateActive(event) {
    const {
      index
    } = event.currentTarget.dataset
    this.setData({
      activeIndex: index
    })
  },

  //监听页面的加载
  onLoad() {
    //调用获取商品分类的数据
    this.getCategoryData()
  }
})